iterating through each row and column